﻿/**
 * 功能:系统自动开放OX活动入口
 */
var setupTask;

function init() {
	scheduleNew();
}

function scheduleNew() {
	var cal = java.util.Calendar.getInstance();
	var hour = cal.get(java.util.Calendar.HOUR_OF_DAY); //获得小时
	var minute = cal.get(java.util.Calendar.MINUTE); //获得分钟
	var second = cal.get(java.util.Calendar.SECOND); //获得秒
	em.setProperty("open", "false");
	cal.set(java.util.Calendar.HOUR, 0);
	cal.set(java.util.Calendar.MINUTE, 30);
	cal.set(java.util.Calendar.SECOND, 0);
	var nextTime = cal.getTimeInMillis();
	while (nextTime <= java.lang.System.currentTimeMillis()) {
		nextTime += 1000 * 60 * 60 * 2; //设置多久开启
	}
	setupTask = em.scheduleAtTimestamp("startEvent", nextTime);
	// 人工开启的话，屏蔽上面的就可以了。
}

function startEvent() {
	em.setProperty("open", "true");
	var cal = java.util.Calendar.getInstance();
	var hour = cal.get(java.util.Calendar.HOUR_OF_DAY); //获得小时
	var minute = cal.get(java.util.Calendar.MINUTE); //获得分钟
	var second = cal.get(java.util.Calendar.SECOND); //获得秒
	if ((hour >= 10 && minute >= 30) && (hour <= 22 && minute <= 40)) {
		cal.set(java.util.Calendar.HOUR, 0);
		cal.set(java.util.Calendar.MINUTE, 30);
		cal.set(java.util.Calendar.SECOND, 0);
		var nextTime = cal.getTimeInMillis();
		while (nextTime <= java.lang.System.currentTimeMillis()) {
			nextTime += 1000 * 60 * 3; //设置多久结束
		}
		setupTask = em.scheduleAtTimestamp("finishEvent", nextTime);
		em.broadcastServerMsg(5121076, "OX宾果活动已经开始拉！请大家速度从PPMS专属副本的宾果活动进来哦！", true);
		em.broadcastServerMsg("[OX宾果活动]  活动入口已经开启，请大家速度从拍卖的宾果活动进来哦！");
		em.broadcastServerMsg("[OX宾果活动]  活动入口已经开启，请大家速度从拍卖的宾果活动进来哦！");
		em.broadcastServerMsg("[OX宾果活动]  活动入口已经开启，请大家速度从拍卖的宾果活动进来哦！");
	}
}

function finishEvent() {
	em.broadcastServerMsg("[OX宾果活动] 活动入口已经关闭，将在每天早上10点30分到晚上10点30分，每隔2个小时开放一次！");
	scheduleNew();
}

function cancelSchedule() {
	if (setupTask != null) {
		setupTask.cancel(true);
	}
}
